<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">主页</a>
		</li>

		<li><span>控制台</span></li>
	</ul>
	<!-- /.breadcrumb -->
</div>




<script type="text/javascript" src="js/laypage.js"></script>
<!-- 第一个tab -->



<script type="text/javascript">
	//重置查询
	function chongZhi() {
		var a = "";
		$.post("pljhd/all", {
			"kssj" : a
		}, function() {
			pageChange(1);
		});
	}

	/* 填充表格 */
	function trList(data) {

		var dataStr = "";
		$.each(data,function(i, a) {$.each(a.pljhd.list,function(i, v) 
		                                {
												dataStr += '<tr>';
												if (v.blrq == null
														|| v.blrq == 'null'
														|| v.blrq == '') {
													dataStr += '<td  class=" blrq'+v.id+'"><input type="hidden" value="'+v.id+'" /><input name="blrq" type="text"  useid="'+v.id+'"  class="caaa  dddd'+i+'" style="width:100px;height:30px "   id="blrq'+v.id+'"   value="'+''+'"  /></td>';
												} else {
													dataStr += '<td  class=" blrq'+v.id+'"><input type="hidden" value="'+v.id+'" /><input name="blrq" type="text" useid="'+v.id+'"  class="caaa  dddd'+i+'" style="width:100px;height:30px " id="blrq'+v.id+'"  value="'+v.blrq+'"  /></td>';
												}
												dataStr += '<td>' + v.xqdh
														+ '</td>';
												dataStr += '<td>' + v.scddh
														+ '</td>';
												dataStr += '<td>' + v.bljhd
														+ '</td>';
												dataStr += '<td>' + v.wlbm
														+ '</td>';
												dataStr += '<td>' + v.wlmc
														+ '</td>';
												dataStr += '<td>' + v.wlsl
														+ '</td>';
												dataStr += '<td>' + v.scxysj
														+ '</td>';
												dataStr += '</tr>';
											});

						});
		// 把拼接好的表格内容填充到指定位置
		$("#tbody_1").html(dataStr);

		$(".caaa").blur(function() {
		
			clickEdit1($(this));
			return false;

		});
		
   
   
		function clickEdit1(obj) {

			var id = obj.attr("useid");
			var blrq = $("#blrq" + id).val();
			//alert(blrq);
			$.post("pljhd/luru", {
				"blrq" : blrq,
				"id" : id
			}, function(data) {//data表示接收后台传递的参数,"wwgs":z,
				pageChange(1);

			});
		}



	}

	$("#selectfromsb").click(function() {

		var kssj = document.getElementById("kssj").value;
		var jssj = document.getElementById("jssj").value;
		if ((kssj == "" && jssj != "") || (kssj != "" && jssj == "")) {
			errorMsg('请输入完整的起始时间和终止时间！');
			document.getElementById("kssj").value = "";
			document.getElementById("jssj").value = "";
			return false;
		} else if (kssj != "" && jssj != "" && kssj >= jssj) {
			errorMsg('终止时间应大于起始时间！');
			document.getElementById("kssj").value = "";
			document.getElementById("jssj ").value = "";
			return false;
		} else {
			$.post("pljhd/all", $("#selefrom").serialize(), function(data) {
				pageChange(1);
			})
			return false;
		}

	});
	//错误提示(传入错误信息)
	function errorMsg(errorInfo) {
		layer.confirm(errorInfo, {
			btn : [ '确定' ]
		//按钮
		}, function(index) {
			layer.close(index);
		});
	}

	function trPost(data) {
		if (data.totalPage != 1) {
			$("#laypage_3").addClass("hide");
			$("#get_pagination3").removeClass("hide");
			laypage({
				cont : $('#get_pagination3'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : data.totalPage, //总页数
				skip : true, //是否开启跳页
				skin : '#2283C5',//保持ace中间的样式
				first : 1,
				last : data.totalPage, //总页数，将尾页显示为总页数
				curr : data.pageNumber,//当前页
				groups : 5, //连续显示分页数
				jump : function(obj, first) {
					if (!first) { //一定要加此判断，否则初始时会无限刷新
						pageChange(obj.curr);
					}
				}
			});
		} else {
			$("#get_pagination3").addClass("hide");
			$("#laypage_3").removeClass("hide");
		}

	}

	function pageChange(curr) {
		$.get("pljhd/all", {
			"pageNumber" : curr
		}, function(data) {
			trList(data); //调用上面trList()方法，填充表格数据
			trPost(data[0].pljhd);
			laypage({
				cont : $('#pages'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : data[0].pljhd.totalPage, //总页数
				skip : true, //是否开启跳页
				skin : 'molv',//设置信息流模式样式
				last : data[0].pljhd.totalPage, //总页数，将尾页显示为总页数
				curr : data[0].pljhd.pageNumber,//当前页
				groups : 3, //连续显示分页数
				jump : function(obj, first) {
					if (!first) { //一定要加此判断，否则初始时会无限刷新
						pageChange(obj.curr);
					}

				}
			});

		});
	}

	function deleteU(id) {

		layer.confirm('是否确定删除？', {
			btn : [ '确定', '取消' ]
		}, function() {
			$.post("pljhd/delete1", {
				"id" : id
			}, function() {
				layer.msg("已删除");
				pageChange(1);
			});
		}, function() {
			layer.msg("已取消");
		});
	}

	pageChange(1);
</script>
<!-- 更改每页显示数据的数目 -->
<script type="text/javascript">
	var sel = document.getElementById("sel");
	sel.onchange = function() {
		/* alert(sel.options[sel.selectedIndex].value); */
		$.post("pljhd/fanye", {
			"infNumber" : sel.options[sel.selectedIndex].value
		}, function(data) {
			pageChange(1);
		});
	}
</script>




<div class="page-content">

	<div class="row">
		<div class="col-xs-12">
			<div class="clearfix"></div>
			<div class="table-header" align="center">配料计划单</div>

			<div>
				<div id="dynamic-table_wrapper"
					class="dataTables_wrapper form-inline no-footer">
					<form method="post" action="pljhd/all" id="selefrom">
						<div class="row">
							<div class="col-xs-12" align="center">
								开始时间：<input type="text" onClick="WdatePicker()"
									style="width:120px;height:30px " ; class="form-control"
									name="kssj" id="kssj" /> 结束时间：<input type="text"
									onClick="WdatePicker()" style="width:120px;height:30px "
									; class="form-control" name="jssj" id="jssj" /> <a
									class="btn btn-sm btn-primary" id="selectfromsb">查询</a> <input
									type="reset" class="btn btn-sm btn-primary"
									onclick="javascript:chongZhi()" value="重置">
							</div>

						</div>
					</form>

					<table
						class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable"
						role="grid">
						<thead>
							<tr role="row">
								<th width="120">备料日期</th>
								<th>需求单号</th>
								<th>生产订单号</th>
								<th>备料计划单号</th>
								<th>物料编码</th>
								<th>物料名称</th>
								<th>物料数量</th>
								<th>生产需要时间（day）</th>
							</tr>
						</thead>
						<tbody id="tbody_1">

						</tbody>

					</table>

					<div class="row">
						<div class="col-xs-12">

							<div class="dataTables_paginate paging_simple_numbers  pull-left">
								<label>显示<select name="dynamic-table_length"
									aria-controls="dynamic-table" class="form-control input-sm"
									id="sel">
										<option value="10">10</option>
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
								</select> 条记录
								</label>
							</div>
							<div class="dataTables_paginate paging_simple_numbers">
								<ul class="pagination" id="get_pagination3">
								</ul>
								<div class="laypage_main laypageskin_molv" id="laypage_3">
									<span class="laypage_curr" style="background-color:#2283C5">1</span><span
										class="laypage_total"><label>到第</label><input max="1"
										min="1" class="laypage_skip" type="number"><label>页</label>
										<button type="button" class="laypage_btn">确定</button> </span>
								</div>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>













<script type="text/javascript">
	jQuery(function($) {
		$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
			_title : function(title) {
				var $title = this.options.title || '&nbsp;';
				if (("title_html" in this.options)
						&& this.options.title_html == true)
					title.html($title);
				else
					title.text($title);
			}
		}));

		//initiate dataTables plugin						初始化表格插件
		/* var oTable1 = $('#dynamic-table')
		//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
		.dataTable({
			bAutoWidth : false,
			"aoColumns" : [ null, null, null, null, null, null, {
				"bSortable" : false
			} ],
			"aaSorting" : [],

		}); */
		//oTable1.fnAdjustColumnSizing();
		//TableTools settings
		TableTools.classes.container = "btn-group btn-overlap";
		TableTools.classes.print = {
			"body" : "DTTT_Print",
			"info" : "tableTools-alert gritter-item-wrapper gritter-info gritter-center white",
			"message" : "tableTools-print-navbar"
		};

		//initiate TableTools extension
		var tableTools_obj = new $.fn.dataTable.TableTools(
				oTable1,
				{
					"sSwfPath" : "plugins/ace/assets/js/dataTables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", //in Ace demo plugins/ace/assets will be replaced by correct assets path

					"sRowSelector" : "td:not(:last-child)",
					"sRowSelect" : "multi",
					"fnRowSelected" : function(row) {
						//check checkbox when row is selected
						try {
							$(row).find('input[type=checkbox]').get(0).checked = true
						} catch (e) {
						}
					},
					"fnRowDeselected" : function(row) {
						//uncheck checkbox
						try {
							$(row).find('input[type=checkbox]').get(0).checked = false
						} catch (e) {
						}
					},

					"sSelectedClass" : "success",
					"aButtons" : [
							{
								"sExtends" : "copy",
								"sToolTip" : "复制到剪贴板",
								"sButtonClass" : "btn btn-white btn-primary btn-bold",
								"sButtonText" : "<i class='fa fa-copy bigger-110 pink'></i>",
								"fnComplete" : function() {
									this.fnInfo(
											'<h3 class="no-margin-top smaller">表格已复制</h3>\
							<p>已复制 '
													+ (oTable1.fnSettings()
															.fnRecordsTotal())
													+ ' 行数据到剪贴板.</p>', 1500);
								}
							},

							{
								"sExtends" : "csv",
								"sToolTip" : "导出成 CSV",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-file-excel-o bigger-110 green'></i>"
							},

							{
								"sExtends" : "pdf",
								"sToolTip" : "导出成 PDF",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-file-pdf-o bigger-110 red'></i>"
							},

							{
								"sExtends" : "print",
								"sToolTip" : "打印页面",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-print bigger-110 grey'></i>",

								"sMessage" : "<div class='navbar navbar-default'><div class='navbar-header pull-left'><a class='navbar-brand' href='#'><small>可选导航栏 &amp; 文本</small></a></div></div>",

								"sInfo" : "<h3 class='no-margin-top'>打印页面</h3>\
							  <p>请用您的浏览器打印功能打印这个表格 \
							  <br />请打印完成关闭此页面</p>",
							} ]
				});

		//we put a container before our table and append TableTools element to it
		$(tableTools_obj.fnContainer()).appendTo($('.tableTools-container'));

		//also add tooltips to table tools buttons
		//addding tooltips directly to "A" buttons results in buttons disappearing (weired! don't know why!)
		//so we add tooltips to the "DIV" child after it becomes inserted
		//flash objects inside table tools buttons are inserted with some delay (100ms) (for some reason)
		setTimeout(function() {
			$(tableTools_obj.fnContainer()).find('a.DTTT_button').each(
					function() {
						var div = $(this).find('> div');
						if (div.length > 0)
							div.tooltip({
								container : 'body'
							});
						else
							$(this).tooltip({
								container : 'body'
							});
					});
		}, 200);

		//ColVis extension
		var colvis = new $.fn.dataTable.ColVis(oTable1, {
			"buttonText" : "<i class='fa fa-search'></i>",
			"aiExclude" : [ 0, 6 ],
			"bShowAll" : true,
			//"bRestore": true,
			"sAlign" : "right",
			"fnLabel" : function(i, title, th) {
				return $(th).text();//remove icons, etc
			}

		});

		//style it
		$(colvis.button()).addClass('btn-group').find('button').addClass(
				'btn btn-white btn-info btn-bold')

		//and append it to our table tools btn-group, also add tooltip
		$(colvis.button()).prependTo('.tableTools-container .btn-group').attr(
				'title', '显示/隐藏 数据列').tooltip({
			container : 'body'
		});

		//and make the list, buttons and checkboxed Ace-like
		$(colvis.dom.collection)
				.addClass(
						'dropdown-menu dropdown-light dropdown-caret dropdown-caret-right')
				.find('li').wrapInner('<a href="javascript:void(0)" />') //'A' tag is required for better styling
				.find('input[type=checkbox]').addClass('ace').next().addClass(
						'lbl padding-8');

		//table checkboxes
		$('th input[type=checkbox], td input[type=checkbox]').prop('checked',
				false);

		//select/deselect all rows according to table header checkbox
		$('#dynamic-table > thead > tr > th input[type=checkbox]').eq(0).on(
				'click',
				function() {
					var th_checked = this.checked;//checkbox inside "TH" table header

					$(this).closest('table').find('tbody > tr').each(
							function() {
								var row = this;
								if (th_checked)
									tableTools_obj.fnSelect(row);
								else
									tableTools_obj.fnDeselect(row);
							});
				});

		//select/deselect a row when the checkbox is checked/unchecked
		$('#dynamic-table').on('click', 'td input[type=checkbox]', function() {
			var row = $(this).closest('tr').get(0);
			if (!this.checked)
				tableTools_obj.fnSelect(row);
			else
				tableTools_obj.fnDeselect($(this).closest('tr').get(0));
		});

		$(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
			e.stopImmediatePropagation();
			e.stopPropagation();
			e.preventDefault();
		});

		//And for the first simple table, which doesn't have TableTools or dataTables
		//select/deselect all rows according to table header checkbox
		var active_class = 'active';
		$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on(
				'click',
				function() {
					var th_checked = this.checked;//checkbox inside "TH" table header

					$(this).closest('table').find('tbody > tr').each(
							function() {
								var row = this;
								if (th_checked)
									$(row).addClass(active_class).find(
											'input[type=checkbox]').eq(0).prop(
											'checked', true);
								else
									$(row).removeClass(active_class).find(
											'input[type=checkbox]').eq(0).prop(
											'checked', false);
							});
				});

		//select/deselect a row when the checkbox is checked/unchecked
		$('#simple-table').on('click', 'td input[type=checkbox]', function() {
			var $row = $(this).closest('tr');
			if (this.checked)
				$row.addClass(active_class);
			else
				$row.removeClass(active_class);
		});

		/********************************/
		//add tooltip for small view action buttons in dropdown menu
		$('[data-rel="tooltip"]').tooltip({
			placement : tooltip_placement
		});

		//tooltip placement on right or left
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table');
			var off1 = $parent.offset();
			var w1 = $parent.width();

			var off2 = $source.offset();
			//var w2 = $source.width();

			if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2))
				return 'right';
			return 'left';
		}

	});
</script>